﻿/// <reference path="TsLinq.d.ts" />
class KeyValuePair<TKey, TValue> implements IKeyValuePair<TKey, TValue>{
    key: TKey;
    value: TValue;
    constructor(key: TKey, value: TValue) {
        this.key = key;
        this.value = value;
    }
}

class KeyValueComparerForKey<TKey, TValue> implements IComparer<IKeyValuePair<TKey, TValue>>{
    keyComparer: IComparer<TKey>;
    constructor(keyComparer?: IComparer<TKey>) {
        this.keyComparer = keyComparer;
    }
    compare(entry1: IKeyValuePair<TKey, TValue>, entry2: IKeyValuePair<TKey, TValue>): number {
        if (this.keyComparer !== undefined) {
            return this.keyComparer.compare(entry1.key, entry2.key);
        }
        if (entry1.key < entry2.key) return -1;
        if (entry1.key == entry2.key) return 0;
        return 1;
    }
}

class KeyValueComparerForValue<TKey, TValue> implements IComparer<IKeyValuePair<TKey, TValue>>{
    valueComparer: IComparer<TValue>;
    constructor(valueComparer?: IComparer<TValue>) {
        this.valueComparer = valueComparer;
    }
    compare(entry1: IKeyValuePair<TKey, TValue>, entry2: IKeyValuePair<TKey, TValue>): number {
        if (this.valueComparer !== undefined) {
            return this.valueComparer.compare(entry1.value, entry2.value);
        }
        if (entry1.value < entry2.value) return -1;
        if (entry1.value == entry2.value) return 0;
        return 1;
    }
}